package t1;

public class Fraction {
	private int numerator;
	private int denominator;
	private String fraction;
	
	public Fraction() {
		super();
		}
	
	public Fraction(int numerator, int denominator) {
		this.numerator = numerator;
		this.denominator = denominator;
		makeItProper();
	}
	
	public int getNumerator() {
		return numerator;
	}
	
	public void setNumerator(int numerator) {
		this.numerator = numerator;
	}
	
	public int getDenominator() {
		return denominator;
	}
	
	public void setDenominator(int denominator) {
		this.denominator = denominator;
	}
	
	public String getFraction() {
		return fraction;
	}
	public void setFraction(String fraction) {
		this.fraction = fraction;
	}
	
    public String creatfraction() 
    {
        numerator = (int) (Math.random() * 20 + 1);
        denominator = (int) (Math.random() * 20 + 1);
        int i = numerator;
        int j = denominator;
        j = GCD(i, j);
        numerator = numerator / j;
        denominator = denominator / j;
        fraction = Reduction(numerator, denominator);
        return fraction;
    }
    
	public static int GCD(int m, int n) {
		while (m % n != 0) {
			int t = m % n;
			m = n;
			n = t;
		}
		return n;
	}
	
	 public void makeItProper() {
		 int commondivisor = Fraction.GCD(numerator, denominator);
		 this.numerator = numerator / commondivisor;
		 this.denominator = denominator / commondivisor;
	 }
	 	

	public static String Reduction(int m, int n) 
    {
        String t;
        if (n == 1) {
            t = m + "";
        } else {
            t = (m) + "" + "/" + (n) + "";
        }
        return t;
    }
}

	
